/*
 * Copyright (C) 2024 Huawei Device Co., Ltd.
 * Licensed under the Apache License, Version 2.0 (the 'License');
 * you may not use this file except in compliance with the License.
 * You may obtain a copy of the License at
 *
 *     http://www.apache.org/licenses/LICENSE-2.0
 *
 * Unless required by applicable law or agreed to in writing, software
 * distributed under the License is distributed on an 'AS IS' BASIS,
 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
 * See the License for the specific language governing permissions and
 * limitations under the License.
 */

#ifndef IMAGE_KNIFE_C_IMAGEKNIFE_TASK_H
#define IMAGE_KNIFE_C_IMAGEKNIFE_TASK_H

#include <memory>
#include <string>
#include "image_data.h"
#include "imageknife_type.h"
#include "image_data_cache.h"

namespace ImageKnifeC {
class ImageKnifeRequest;
class ImageSource;
class Interceptor;

class ImageKnifeTask {
public:
    struct Product {
        // 原始图片buffer
        std::shared_ptr<uint8_t[]> imageBuffer = nullptr;
        // 原始图片长度
        uint32_t imageLength = 0;
        // 图片pixelmap数据, 单帧或多帧
        std::shared_ptr<ImageData> imageData = nullptr;
        // 图片数据缓存对象，用于显示渲染
        std::shared_ptr<ImageDataCache> imageDataCache = nullptr;
        // 标识内存缓存/文件缓存拦截器的任务类型
        CacheTaskType cacheType = CacheTaskType::NONE;
    };

    // 加载任务的产品
    Product product;
    // 记录取消时的额外信息，会附加至cancel回调中
    std::string cancelInfo;
    // 记录网络下载http状态码
    int httpCode = 0;
    // 记录加载中产生的错误码，会统计到数据采集中
    int errorCode = 0;

    virtual ~ImageKnifeTask() = default;
    // 输出错误信息，会附带上组件ID，Version，RequestType，以及所在的拦截器名称，便于定位
    virtual void EchoError(std::string errorInfo) = 0;
    // 加载的组件是否未Animator组件
    virtual bool IsAnimator() const = 0;
    // 获取加载成功后的图片buffer的编码格式, 在buffer加载完成前调用返回UNKOWN
    virtual ImageFormat GetImageBufferFormat() const = 0;
    // 获取加载任务ImageSource
    virtual ImageSource *GetImageSource() const = 0;
    // 获取加载任务的请求类型
    virtual ImageRequestType GetImageRequestType() const = 0;
    // 获取ImageKnifeRequest对象
    virtual std::shared_ptr<ImageKnifeRequest> GetImageKnifeRequest() const = 0;
};

}

#endif // IMAGE_KNIFE_C_IMAGEKNIFE_TASK_H
